package com.bfl.sa.maintain.notification.service;

import com.bfl.sa.common.service.BaseService;
import com.bfl.sa.maintain.notification.entity.NotificationData;
import com.bfl.sa.maintain.notification.mapper.NotificationDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class NotificationDataService extends BaseService<NotificationData, Long> {

    @Resource
    private NotificationDataMapper notificationDataMapper;

    public void markReadAll(final Long userId) {
        notificationDataMapper.markReadAll(userId);
    }

    public void markRead(final Long notificationId) {
        NotificationData data = findOne(notificationId);
        if(data == null || data.getRead().equals(Boolean.TRUE)) {
            return;
        }
        data.setRead(Boolean.TRUE);
        update(data);
    }

}
